﻿
@{
    ViewBag.Title = "编辑发货单";
    Layout = "~/Views/Shared/_LayoutPage.cshtml";

    var warehouses = ViewBag.Warehouses as List<IOA.MES.DataAccess.VModel.VWarehouse>;
}
@model IOA.MES.DataAccess.VModel.VDeliveryOrder

@section Contents{
    <style>
        html {
            background-color: #FFF;
        }

        .layui-form-item .layui-input-inline {
            width: 300px;
        }

        .red {
            color: red;
        }
    </style>
}

<div id="page"></div>

<script type="text/template" id="tplPage">
    <div class="layui-form" lay-filter="layuiadmin-app-form-list" style="padding: 20px 30px;">
        <div class="layui-form-item">
            <label class="layui-form-label"><span class="red">*</span>{{lang.Field.DeliveryNo}}：</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" name="DeliveryNo" value="@(Model?.DeliveryNo)" @(string.IsNullOrWhiteSpace(Model?.DeliveryNo) ? "" : " readonly ") lay-verify="required" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span class="red">*</span>{{lang.Field.OrderNo}}：</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" name="OrderNo" value="@(Model?.OrderNo)" lay-verify="required">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span class="red">*</span>{{lang.Field.ContractNo}}：</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" name="ContractNo" value="@(Model?.ContractNo)" lay-verify="required">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span class="red">*</span>{{lang.Field.DeliveryWarehouse}}：</label>
            <div class="layui-input-inline">
                <select name="WarehouseCode" lay-verify="required">
                    <option value=""></option>
                    @foreach (var item in warehouses)
                    {
                        <option value="@item.WarehouseCode" @(string.Equals(item.WarehouseCode, Model?.WarehouseCode, StringComparison.CurrentCultureIgnoreCase) ? " selected" : "")>@item.WarehouseName</option>
                    }
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">{{lang.Field.CustomerCode}}：</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" name="CustomerCode" value="@(Model?.CustomerCode)">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">{{lang.Field.CustomerName}}：</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" name="CustomerName" value="@(Model?.CustomerName)">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span class="red">*</span>{{lang.Field.DeliveryDate}}：</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" name="DeliveryDate" value="@(Model?.DeliveryDate?.ToString("yyyy-MM-dd"))" lay-verify="required">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span class="red">*</span>{{lang.Field.Quantity}}：</label>
            <div class="layui-input-inline">
                <input type="number" class="layui-input" name="Count" value="@(Model?.Count)" lay-verify="required">
            </div>
        </div>
        <div class="layui-form-item" style="text-align:center;padding-top: 20px;">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="submit"><i class="layui-icon">&#xe605;</i>{{lang.Field.Submit}}</button>
            <button class="layui-btn layui-btn-primary" onclick="parent.layer.close(parent.layer.getFrameIndex(window.name));"><i class="layui-icon">&#xe616;</i>{{lang.Field.Cancel}}</button>
        </div>
    </div>
</script>

@section Scripts{
    <script>
        var vm = new Vue({
            el: "#page",
            template: "#tplPage",
            data: {
                lang: JSON.parse(lang).package
            }
        });
        setTimeout(function () {
            initLayui();
        }, 50);
        function initLayui() {
            layui.use(['form', 'layer', 'index', 'laydate'], function () {
                var layer = layui.layer,
                    form = layui.form,
                    laydate = layui.laydate;
                laydate.render({
                    elem: 'input[name=DeliveryDate]'
                    , type: 'date'
                });

                form.on('submit(submit)', function (data) {
                    console.log(data.field);
                    if (data.field.Count.trim() == "" || parseInt(data.field.Count.trim()) <= 0) {
                        return layer.msg("数量必须大于0", { icon: 5 });
                    }

                    var loadId = layer.load();
                    $.ajax({
                        url: "/Plan/SaveDelivery",
                        data: data.field,
                        complete: function () {
                            layer.close(loadId);
                        },
                        success: function (res) {
                            if (res.ErrCode != 200) {
                                layer.msg(res.ErrMsg, { icon: 5 });
                                return;
                            }
                            layer.msg("保存成功！", { icon: 6, time: 1500 }, function () {
                                parent.layer.close(parent.layer.getFrameIndex(window.name));
                            });
                        }
                    });
                    return false;
                });
            });
        }
    </script>
}
